ENTRY INT FUNC Delete (REF INT length, INT ARRAY heap) INT new, lengthdiv2, root, son, cur, next, last IF length=0 THEN RETURN(0) FI last := heap(length) new := heap(1) length := length-1 lengthdiv2 := length RSH 1 root := 1 son := 2 WHILE root <= lengthdiv2 DO cur := heap(son) next := heap(son+1) IF next < cur THEN cur := next son := son+1 FI IF cur <= last THEN heap(root) := cur root := son son := root LSH 1 ELSE EXIT FI OD heap(root) := last heap(length) := #77777 (* #77777 is plus infinity. *) RETURN(new)
ENTRY PROC Insert(REF INT length, INT ARRAY heap, INT new) INT i, idiv2, cur i := length+1 length := i idiv2 := i RSH 1 cur := heap(idiv2) WHILE new < cur DO heap(i) := cur i := idiv2 idiv2 := i RSH 1 cur := heap(idiv2) OD heap(i) := new RETURN